/**
 * <copyright>
 * </copyright>
 *

 */
package ms.unicorn.language.languagedef.impl;

import java.util.Collection;

import ms.unicorn.language.languagedef.ConnectionDecorator;
import ms.unicorn.language.languagedef.ConnectionStyleDef;
import ms.unicorn.language.languagedef.LanguagedefPackage;
import ms.unicorn.language.languagedef.LineStyle;
import ms.unicorn.language.languagedef.XReferenceExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Connection Style Def</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#isWidthSet <em>Width Set</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#getWidth <em>Width</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#isLineStyleSet <em>Line Style Set</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#getStyle <em>Style</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#isColorSet <em>Color Set</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#getColor <em>Color</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.ConnectionStyleDefImpl#getDecorators <em>Decorators</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ConnectionStyleDefImpl extends ModuleItemImpl implements ConnectionStyleDef
{
  /**
   * The default value of the '{@link #isWidthSet() <em>Width Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isWidthSet()
   * @generated
   * @ordered
   */
  protected static final boolean WIDTH_SET_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isWidthSet() <em>Width Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isWidthSet()
   * @generated
   * @ordered
   */
  protected boolean widthSet = WIDTH_SET_EDEFAULT;

  /**
   * The default value of the '{@link #getWidth() <em>Width</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getWidth()
   * @generated
   * @ordered
   */
  protected static final int WIDTH_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getWidth() <em>Width</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getWidth()
   * @generated
   * @ordered
   */
  protected int width = WIDTH_EDEFAULT;

  /**
   * The default value of the '{@link #isLineStyleSet() <em>Line Style Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isLineStyleSet()
   * @generated
   * @ordered
   */
  protected static final boolean LINE_STYLE_SET_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isLineStyleSet() <em>Line Style Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isLineStyleSet()
   * @generated
   * @ordered
   */
  protected boolean lineStyleSet = LINE_STYLE_SET_EDEFAULT;

  /**
   * The default value of the '{@link #getStyle() <em>Style</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStyle()
   * @generated
   * @ordered
   */
  protected static final LineStyle STYLE_EDEFAULT = LineStyle.NONE;

  /**
   * The cached value of the '{@link #getStyle() <em>Style</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStyle()
   * @generated
   * @ordered
   */
  protected LineStyle style = STYLE_EDEFAULT;

  /**
   * The default value of the '{@link #isColorSet() <em>Color Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isColorSet()
   * @generated
   * @ordered
   */
  protected static final boolean COLOR_SET_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isColorSet() <em>Color Set</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isColorSet()
   * @generated
   * @ordered
   */
  protected boolean colorSet = COLOR_SET_EDEFAULT;

  /**
   * The cached value of the '{@link #getColor() <em>Color</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getColor()
   * @generated
   * @ordered
   */
  protected XReferenceExpression color;

  /**
   * The cached value of the '{@link #getDecorators() <em>Decorators</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDecorators()
   * @generated
   * @ordered
   */
  protected EList<ConnectionDecorator> decorators;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ConnectionStyleDefImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return LanguagedefPackage.Literals.CONNECTION_STYLE_DEF;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isWidthSet()
  {
    return widthSet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setWidthSet(boolean newWidthSet)
  {
    boolean oldWidthSet = widthSet;
    widthSet = newWidthSet;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH_SET, oldWidthSet, widthSet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getWidth()
  {
    return width;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setWidth(int newWidth)
  {
    int oldWidth = width;
    width = newWidth;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH, oldWidth, width));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isLineStyleSet()
  {
    return lineStyleSet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setLineStyleSet(boolean newLineStyleSet)
  {
    boolean oldLineStyleSet = lineStyleSet;
    lineStyleSet = newLineStyleSet;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__LINE_STYLE_SET, oldLineStyleSet, lineStyleSet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public LineStyle getStyle()
  {
    return style;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setStyle(LineStyle newStyle)
  {
    LineStyle oldStyle = style;
    style = newStyle == null ? STYLE_EDEFAULT : newStyle;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__STYLE, oldStyle, style));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isColorSet()
  {
    return colorSet;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setColorSet(boolean newColorSet)
  {
    boolean oldColorSet = colorSet;
    colorSet = newColorSet;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR_SET, oldColorSet, colorSet));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XReferenceExpression getColor()
  {
    return color;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetColor(XReferenceExpression newColor, NotificationChain msgs)
  {
    XReferenceExpression oldColor = color;
    color = newColor;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR, oldColor, newColor);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setColor(XReferenceExpression newColor)
  {
    if (newColor != color)
    {
      NotificationChain msgs = null;
      if (color != null)
        msgs = ((InternalEObject)color).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR, null, msgs);
      if (newColor != null)
        msgs = ((InternalEObject)newColor).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR, null, msgs);
      msgs = basicSetColor(newColor, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR, newColor, newColor));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ConnectionDecorator> getDecorators()
  {
    if (decorators == null)
    {
      decorators = new EObjectContainmentEList<ConnectionDecorator>(ConnectionDecorator.class, this, LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS);
    }
    return decorators;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR:
        return basicSetColor(null, msgs);
      case LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS:
        return ((InternalEList<?>)getDecorators()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH_SET:
        return isWidthSet();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH:
        return getWidth();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__LINE_STYLE_SET:
        return isLineStyleSet();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__STYLE:
        return getStyle();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR_SET:
        return isColorSet();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR:
        return getColor();
      case LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS:
        return getDecorators();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH_SET:
        setWidthSet((Boolean)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH:
        setWidth((Integer)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__LINE_STYLE_SET:
        setLineStyleSet((Boolean)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__STYLE:
        setStyle((LineStyle)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR_SET:
        setColorSet((Boolean)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR:
        setColor((XReferenceExpression)newValue);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS:
        getDecorators().clear();
        getDecorators().addAll((Collection<? extends ConnectionDecorator>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH_SET:
        setWidthSet(WIDTH_SET_EDEFAULT);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH:
        setWidth(WIDTH_EDEFAULT);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__LINE_STYLE_SET:
        setLineStyleSet(LINE_STYLE_SET_EDEFAULT);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__STYLE:
        setStyle(STYLE_EDEFAULT);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR_SET:
        setColorSet(COLOR_SET_EDEFAULT);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR:
        setColor((XReferenceExpression)null);
        return;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS:
        getDecorators().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH_SET:
        return widthSet != WIDTH_SET_EDEFAULT;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__WIDTH:
        return width != WIDTH_EDEFAULT;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__LINE_STYLE_SET:
        return lineStyleSet != LINE_STYLE_SET_EDEFAULT;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__STYLE:
        return style != STYLE_EDEFAULT;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR_SET:
        return colorSet != COLOR_SET_EDEFAULT;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__COLOR:
        return color != null;
      case LanguagedefPackage.CONNECTION_STYLE_DEF__DECORATORS:
        return decorators != null && !decorators.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (widthSet: ");
    result.append(widthSet);
    result.append(", width: ");
    result.append(width);
    result.append(", lineStyleSet: ");
    result.append(lineStyleSet);
    result.append(", style: ");
    result.append(style);
    result.append(", colorSet: ");
    result.append(colorSet);
    result.append(')');
    return result.toString();
  }

} //ConnectionStyleDefImpl
